function alertNew(info, w, h, contId) {
	layui.use(['layer', 'form'], function() {
		var layer = layui.layer;
		var form = layui.form;
		layer.open({
			type: 1,
			title: info,
			area: [w + 'px', h + 'px'],
			content: contId //这里content是一个普通的String
		});

	});
}

function closeThis() {

	layer.closeAll();

}

function prompt(info) {
	layui.use('layer', function() {
		var layer = layui.layer;

		layer.open({
			title: '提示',
			content: info
		});
	});
}
$.ajaxSetup({
	complete: function(jqXHR) {
		
		if(jqXHR.status == 304) {

			window.location.href = "#/"
		}
		var shielding = [902, 901, 304, 903, 401]; //拦截状态码

		if(shielding.indexOf(jqXHR.status) != -1) {
			window.location.href = "#/";

		}
	},
	error: function(jqXHR, textStatus, errorThrown) {

		var shielding = [902, 901, 304, 903, 401]; //拦截状态码
		if(shielding.indexOf(jqXHR.status) != -1) {
			window.location.href = "#/";

		}
	}
});

function date(value) {
	if(value || value == 0) {
		var date = new Date(value)
		
		var newDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " " + date.getHours() + ":" +zeroNum(date.getMinutes())  + ":" +zeroNum(date.getSeconds()) 
			// console.log(newDate)
		return newDate;
	} else {
		return "-"
	}

}

function date2(value){
	var date = new Date(value)
    var newDate = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate()
    return newDate;
	
}

function zeroNum(num){
	return num=num<10 ? '0'+num: num;

	
	
}

//点击查询
function lookSearch(clickObj, user, table) {
	clickObj.click(function() {
		table.bootstrapTable('refresh', {
			query: {
				mtLogin: user.val(),

			}

		});

	})

}
//转换钱格式
function changeMoney(money) {
	return money.toLocaleString()
}

function txFuction(value, row, index) {
	if(row.iconUrl!=null){
	return "<img src=" + row.iconUrl + " class='listTx'/> <span>" + value + "</span>"
		
	}else{
	   return "<img src='img/timg.png' class='listTx'/> <span>" + value + "</span>"
		
	}


}

function hand(value) {
	return (value / 100).toFixed(2)
}

function type(value) {

	if(value || value == 0) {

		if(value == 0) {
			return "<span class='red'>SELL</span>"
		} else {
			return "<span class='green'>BUY</span>"
		}
	} else {
		return "-"
	}

}

function ping(value, row, index) {
	var info = JSON.stringify(row)
	return [
		"<button type='button' class='layui-btn layui-btn-normal' onclick='pingYes(" + info + ")'>立即平仓</button>",

	].join("")
}

function ponity(value) {
	if(value || value == 0) {
		if(value > 0) {
			return "<span class='green'>" + value + "点<span>";
		} else {
			return "<span class='red'>" + value + "点<span>";
		}
	}

}

function money(value) {
	if(value || value == 0) {
		if(value > 0) {
			return "<span class='green'>" + value + "<span>";
		} else {
			return "<span class='red'>" + value + "<span>";
		}
	} else {
		return "-"
	}

}

function pingYes(info) {
		layui.use('layer', function() {
			var layer = layui.layer;
			layer.open({
				content: '您确定平仓吗？',
				btn: ['确定', '取消'],
				yes: function(index, layero) {
					$.ajax({
						type: "put",
						url: "/wechat_mt5/mt/user/close/trade",
						data: {
							order: info.order,
						},
						success: function(data) {
							if(data.code == 0) {
								if(data.data) {
									prompt("平仓成功！");
									$('#myChiList').bootstrapTable(
										"refresh", {
											url: "/wechat_mt5/mt/user/web/myself/position"
										}
									);

								} else {
									prompt("平仓失败！");
								}

								$scope.$apply();
							}

						}
					});
				},
				btn2: function(index, layero) {
					layer.close(index)
						//按钮【按钮二】的回调

					//return false 开启该代码可禁止点击该按钮关闭
				}
			});

		});
	}
   
	

//window.onbeforeunload = function() {
//     $.ajax({
//			type: "get",
//			url: "/wechat_mt5/user/logout",
//			success: function(data) {
//				if(data.code == 0) {
//					window.location.href = "#/";
//
//				}
//			}
//
//		})
//}